package com.javastar.modules.security.exception;

import com.javastar.common.exception.ErrorCode;
import com.javastar.common.result.Result;
import com.javastar.common.utils.ResponseUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 无凭证异常处理器
 *
 * @author zxx
 * @date 2023/7/26
 */
@Component
public class SysAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        ResponseUtil.write(response, new Result().error(ErrorCode.TOKEN_EMPTY));
    }
}
